package com.situ.mall.manager.mapper;

import com.situ.mall.manager.entity.GoodsPic;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface GoodsPicMapper {

    /**
     * 批量插入图片
     * @param pics
     * @return
     */
    @Insert({
            "<script>",
            "insert into goods_pic",
            "(url,goods_id)",
            "value",
            "<foreach collection='pics' item='pic' separator=','>",
            "(#{pic.url},#{pic.goodsId})",
            "</foreach>",
            "</script>",
    })
    int insert(@Param("pics") List<GoodsPic> pics);

    /**
     * 根据商品id删除
     * @param goodsId
     * @return
     */
    @Delete("delete from goods_pic where goods_id=#{goodsId}")
    int deleteByGoodsId(Integer goodsId);

    /**
     * 根据id查询
     * @param goodsId
     * @return
     */
    @Select("select * from goods_pic where goods_id=#{goodsId}")
    List<GoodsPic> selectByGoodsId(Integer goodsId);
}
